package com.qfjy.controller;

import com.qfjy.client.VideoInfoFeignClient;
import com.qfjy.common.utils.result.ResultCode;
import com.qfjy.common.utils.result.ResultJson;
import com.qfjy.entity.po.MeetingPub;
import com.qfjy.service.MeetingPubService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;

/**
 * @ClassName MeetingPubController
 * @Description TODO
 * @Author guoweixin
 * @Date 2022/12/13
 * @Version 1.0
 */
@Controller
@Slf4j
@RequestMapping("meetingPub")
public class MeetingPubController {

    @Autowired
    private MeetingPubService meetingPubService;

    /**
     * 根据会议编号 查询会议信息
     *  meetingPub/select?pcode=11111
     */
    @GetMapping("select")
    @ResponseBody
    public ResultJson selectMeetingPubByPcode(@RequestParam("pcode") String pcode){

        MeetingPub meetingPub=meetingPubService.selectMeetingPubByPcode(pcode);
        log.info("查询会议微服务{}",meetingPub);

        if(meetingPub==null){
            return  new ResultJson(null, ResultCode.NOT_DATA);
        }

        //调用视频微服务接口  RestTemplate
      //  String url="http://localhost:8081/videoInfo/select?pcode="+meetingPub.getPcode();
      //  String result=restTemplate.getForObject(url,String.class);


        // Ribbon+RestTemplate
        //Ribbon与Eureka配合使用时，Ribbon可自动从Eureka Server获取服务提供者地址列表，并基于负载均衡算法，请求其中一个服务提供者实例。
       // String url="http://SANFI-VIDEO/videoInfo/select?pcode="+meetingPub.getPcode();
      //  String result=restTemplate.getForObject(url,String.class);


        //feign实现服务间通信
        String result=videoInfoFeignClient.selectVideoInfoByPcode(pcode);
         meetingPub.setRemark(result);
         log.info("调用视频微服务{}",result);


        String result1= videoInfoFeignClient.selectVideoInfoByPcode1("123");
         log.info("调用的是另一个方法：{}",result1);

         meetingPub.setTitle(result1);
        return new ResultJson(meetingPub,ResultCode.SUCCESS);
    }

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private VideoInfoFeignClient videoInfoFeignClient;
}
